﻿Imports System.IO
Imports System
Imports System.Linq
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports GeoFramework
Imports GeoFramework.Gps
Imports GeoFramework.Gps.IO
Imports GeoFramework.Gps.Nmea


Public Class frmParamGPS

    Public oCurrentDevice As Device
    Public NmeaInterpreter1 As New GeoFramework.Gps.Nmea.NmeaInterpreter()
    Private strLatitude As String = ""
    Private strLongitude As String = ""
    Private strAltitude As String = "00000"
    Private strHDOP As String = ""
    Private strGPSparam As String
    Public blGpsON As Boolean = False
    Public oldDateTimeTrackRec As DateTime
    Dim GpsStatus As CtlLightGPSTrack.GpsLightStatus


    'Déclaration du délégué d'affichage de track GPS
    ' Private Delegate Sub DelegateAfficherDataTrack(ByVal wLatitude As String, ByVal wLongitude As String, _
    '  ByVal wDop As String, ByVal wAltitude As String)
    ' Private pAfficherDataTrack As New DelegateAfficherDataTrack(AddressOf AfficherDataTrack)

    Sub New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        Show()
        Application.DoEvents()
        m_isFormGPSOpen = True

        AddHandler Devices.DeviceDetectionStarted, AddressOf Devices_DeviceDetectionStarted
        AddHandler Devices.DeviceDetected, AddressOf Devices_DeviceDetected
        AddHandler Devices.DeviceDetectionCompleted, AddressOf Devices_DeviceDetectionCompleted
        AddHandler Devices.DeviceDetectionAttempted, AddressOf Devices_DeviceDetectionAttempted
        AddHandler Devices.DeviceDetectionAttemptFailed, AddressOf Devices_DeviceDetectionAttemptFailed

        AddHandler NmeaInterpreter1.SpeedChanged, AddressOf NmeaInterpreter1_SpeedChanged
        AddHandler NmeaInterpreter1.FixAcquired, AddressOf NmeaInterpreter1_FixAcquired
        AddHandler NmeaInterpreter1.FixLost, AddressOf NmeaInterpreter1_FixLost
        AddHandler NmeaInterpreter1.Resumed, AddressOf NmeaInterpreter1_Resumed
        AddHandler NmeaInterpreter1.FixModeChanged, AddressOf NmeaInterpreter1_FixModeChanged
        AddHandler NmeaInterpreter1.FixQualityChanged, AddressOf NmeaInterpreter1_FixQualityChanged
        AddHandler NmeaInterpreter1.HorizontalDilutionOfPrecisionChanged, AddressOf NmeaInterpreter1_HorizontalDilutionOfPrecisionChanged
        AddHandler NmeaInterpreter1.AltitudeChanged, AddressOf NmeaInterpreter1_AltitudeChanged
        AddHandler NmeaInterpreter1.PositionChanged, AddressOf NmeaInterpreter1_PositionChanged
        AddHandler NmeaInterpreter1.UtcDateTimeChanged, AddressOf NmeaInterpreter1_UtcDateTimeChanged
        AddHandler NmeaInterpreter1.Paused, AddressOf NmeaInterpreter1_Paused
        AddHandler NmeaInterpreter1.BearingChanged, AddressOf NmeaInterpreter1_BearingChanged
        AddHandler NmeaInterpreter1.VerticalDilutionOfPrecisionChanged, AddressOf NmeaInterpreter1_VerticalDilutionOfPrecisionChanged
        AddHandler NmeaInterpreter1.SatellitesChanged, AddressOf NmeaInterpreter1_SatellitesChanged
        'Timer
        Timer1.Enabled = True
        Timer1.Interval = 500
        AddHandler Timer1.Tick, AddressOf Timer1_Tick

        'Compass1.IsPaintingOnSeparateThread = False
        frmUtilitycompass.Compass1.IsPaintingOnSeparateThread = False
        'altimeter1.IsPaintingOnSeparateThread = False
        'speedometer1.IsPaintingOnSeparateThread = False
        ' SatelliteViewer1.IsPaintingOnSeparateThread = False
        frmUtilitycompass.SatelliteViewer1.IsPaintingOnSeparateThread = False
        'SatelliteSignalBar1.IsPaintingOnSeparateThread = False

        ' GeoFramework.Gps.Diagnostics.Run(New StreamWriter("GPS Diagnostics Log.txt"))

    End Sub
#Region "GPS Device : Detection des évènements"

    Private Sub Devices_DeviceDetectionStarted(ByVal sender As Object, ByVal e As EventArgs)
        BeginInvoke(New Action(Of Object, EventArgs)(AddressOf DeviceDetectionStarted), sender, e)
    End Sub
    Private Sub DeviceDetectionStarted(ByVal sender As Object, ByVal e As EventArgs)
        StatusBar2.Text = My.Resources.Images.paramGpsSearchApp.ToString()
        SearchButton.Enabled = False
        frmUtilityTracks.Txt_TrackStatus.Text = "false"
    End Sub


    Private Sub Devices_DeviceDetected(ByVal sender As Object, ByVal e As DeviceEventArgs)
        BeginInvoke(New Action(Of Object, EventArgs)(AddressOf DeviceDetected), sender, e)
    End Sub
    Private Sub DeviceDetected(ByVal sender As Object, ByVal e As DeviceEventArgs)
        StatusBar2.Text = My.Resources.Images.paramGpsFindedApp.ToString() & e.Device.ToString()
        Dim DeviceItem As New ListViewItem(e.Device.ToString())
        '  Associate the detected device with this list view item, so we can connect to the device later on
        DeviceItem.Tag = e.Device
        'Set the image of the new item
        DeviceItem.ImageIndex = 0
        DevicesListView.Items.Add(DeviceItem)
        DevicesListView.Items(0).Selected = True
    End Sub

    Private Sub Devices_DeviceDetectionCompleted(ByVal sender As Object, ByVal e As EventArgs)
        BeginInvoke(New Action(Of Object, EventArgs)(AddressOf DeviceDetectionCompleted), sender, e)
    End Sub
    Private Sub DeviceDetectionCompleted(ByVal sender As Object, ByVal e As EventArgs)
        StatusBar2.Text = My.Resources.Images.paramGpsDetectComplete.ToString
        SearchButton.Enabled = True
        StartButton.Enabled = True
    End Sub

    Private Sub Devices_DeviceDetectionAttempted(ByVal sender As Object, ByVal e As DeviceEventArgs)
        BeginInvoke(New Action(Of Object, EventArgs)(AddressOf DeviceDetectionAttempted), sender, e)
    End Sub
    Private Sub DeviceDetectionAttempted(ByVal sender As Object, ByVal e As DeviceEventArgs)
        StatusBar2.Text = "Detection  " & e.Device.ToString()
    End Sub

    Private Sub Devices_DeviceDetectionAttemptFailed(ByVal sender As Object, ByVal e As DeviceDetectionExceptionEventArgs)
        BeginInvoke(New Action(Of Object, EventArgs)(AddressOf DeviceDetectionAttemptFailed), sender, e)
    End Sub
    Private Sub DeviceDetectionAttemptFailed(ByVal sender As Object, ByVal e As DeviceDetectionExceptionEventArgs)
        StatusBar2.Text = My.Resources.Images.paramGpsError.ToString() & ": " & e.Exception.ToString()
    End Sub

    Private Sub SearchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchButton.Click
        Me.DevicesListView.Clear()
        If (Not IsNothing(oCurrentDevice)) Then
            If (oCurrentDevice.IsOpen) Then StopGPS(False)
        End If
        GeoFramework.Gps.IO.Devices.BeginDetection()
    End Sub

#End Region


#Region "interpreteur NMEA: Detection des évènements"
    Private Sub NmeaInterpreter1_AltitudeChanged(ByVal sender As Object, ByVal e As GeoFramework.DistanceEventArgs)
        BeginInvoke(New Action(Of Object, GeoFramework.DistanceEventArgs)(AddressOf AltitudeChanged), sender, e)
    End Sub

    Private Sub AltitudeChanged(ByVal sender As Object, ByVal e As GeoFramework.DistanceEventArgs)
        ' altimeter1.Value = e.Distance
        oCurrentGpsPosition.altitude = e.Distance.ToMeters.Value
        Altitude.Text = oCurrentGpsPosition.roundAltitude.ToString & " m"

        ' ajouter données au track
        ' AfficherDataTrack(strLatitude, strLongitude, strHDOP, strAltitude)
    End Sub

    Private Sub NmeaInterpreter1_SpeedChanged(ByVal sender As System.Object, ByVal e As GeoFramework.SpeedEventArgs)
        BeginInvoke(New Action(Of Object, GeoFramework.SpeedEventArgs)(AddressOf SpeedChanged), sender, e)

    End Sub

    Private Sub SpeedChanged(ByVal sender As Object, ByVal e As GeoFramework.SpeedEventArgs)
        'speedometer1.Value = e.Speed
        'Update the current speed
        Speed.Text = e.Speed.ToLocalUnitType().ToString()
        StatusBar2.Text = "Speed has changed."
    End Sub

    Private Sub NmeaInterpreter1_FixAcquired(ByVal sender As System.Object, ByVal e As System.EventArgs)
        BeginInvoke(New Action(Of Object, System.EventArgs)(AddressOf FixAcquired), sender, e)

    End Sub

    Private Sub FixAcquired(ByVal sender As Object, ByVal e As System.EventArgs)

        'Change the fix status            
        FixStatus.Text = "Fix Obtained!"
        StatusBar2.Text = "A fix has been obtained!"

    End Sub

    Private Sub NmeaInterpreter1_FixLost(ByVal sender As System.Object, ByVal e As System.EventArgs)

        BeginInvoke(New Action(Of Object, System.EventArgs)(AddressOf FixLost), sender, e)

    End Sub

    Private Sub FixLost(ByVal sender As Object, ByVal e As System.EventArgs)

        'Change the fix status
        FixStatus.Text = "Fix Lost"
        StatusBar2.Text = "The current fix was lost."

    End Sub

    Private Sub NmeaInterpreter1_Resumed(ByVal sender As System.Object, ByVal e As System.EventArgs)
        BeginInvoke(New Action(Of Object, System.EventArgs)(AddressOf Resumed), sender, e)

    End Sub

    Private Sub Resumed(ByVal sender As Object, ByVal e As System.EventArgs)

        Cursor.Current = Cursors.Default
        StatusBar2.Text = "Device is no longer suspended! Restarting..."

    End Sub

    Private Sub NmeaInterpreter1_FixModeChanged(ByVal sender As System.Object, ByVal e As GeoFramework.Gps.FixModeEventArgs)
        BeginInvoke(New Action(Of Object, GeoFramework.Gps.FixModeEventArgs)(AddressOf FixModeChanged), sender, e)

    End Sub

    Private Sub FixModeChanged(ByVal sender As Object, ByVal e As GeoFramework.Gps.FixModeEventArgs)

        ' Update the current fix mode
        FixMode.Text = e.FixMode.ToString()
        StatusBar2.Text = "Fix mode has changed."

    End Sub

    Private Sub NmeaInterpreter1_FixQualityChanged(ByVal sender As System.Object, ByVal e As GeoFramework.Gps.FixQualityEventArgs)
        BeginInvoke(New Action(Of Object, GeoFramework.Gps.FixQualityEventArgs)(AddressOf FixQualityChanged), sender, e)

    End Sub

    Private Sub FixQualityChanged(ByVal sender As Object, ByVal e As GeoFramework.Gps.FixQualityEventArgs)
        ' Update the current fix quality
        FixQuality.Text = e.FixQuality.ToString()
        StatusBar2.Text = "Fix quality has changed."
    End Sub

    Private Sub NmeaInterpreter1_HorizontalDilutionOfPrecisionChanged(ByVal sender As System.Object, ByVal e As GeoFramework.Gps.DilutionOfPrecisionEventArgs)
        BeginInvoke(New Action(Of Object, GeoFramework.Gps.DilutionOfPrecisionEventArgs)(AddressOf HorizontalDilutionOfPrecisionChanged), sender, e)

    End Sub

    Private Sub HorizontalDilutionOfPrecisionChanged(ByVal sender As Object, ByVal e As GeoFramework.Gps.DilutionOfPrecisionEventArgs)
        'Update the horizontal DOP on the track bar
        oCurrentGpsPosition.dopH = e.DilutionOfPrecision.Value

        If CInt(e.DilutionOfPrecision.Value) < 49 Then
            GpsStatus = CtlLightGPSTrack.GpsLightStatus.statusOn
            ChangeCtlLightGpsStatus(GpsStatus)
            txt_currentprecisionH.Text = oCurrentGpsPosition.roundPrecisionH.ToString & " m"
            oCurrentGpsPosition.altitude = Nothing
            oCurrentGpsPosition.latitude = Nothing
            oCurrentGpsPosition.longitude = Nothing
        Else
            GpsStatus = CtlLightGPSTrack.GpsLightStatus.statusOnWithoutSignal

            txt_currentprecisionH.Text = "NO"
            ChangeCtlLightGpsStatus(GpsStatus)
        End If
        strHDOP = e.DilutionOfPrecision.Value

        StatusBar2.Text = "Lat/long precision has changed."

        CalculatePrecision(oCurrentGpsPosition.dopH, Me.preci_cadre.Width, Preci, LabelTxtSignalQuality)

        'strHDOP = CurrentHdopTrackBar.Value
        ' ajouter données au track
        'AfficherDataTrack(strLatitude, strLongitude, strHDOP, strAltitude)
    End Sub

    Private Sub NmeaInterpreter1_PositionChanged(ByVal sender As System.Object, ByVal e As GeoFramework.PositionEventArgs)
        BeginInvoke(New Action(Of Object, GeoFramework.PositionEventArgs)(AddressOf PositionChanged), sender, e)
    End Sub

    Private Sub PositionChanged(ByVal sender As Object, ByVal e As GeoFramework.PositionEventArgs)
        ' Update the lati/*-tude and longitude


        If e.Position.Latitude.ToString() <> "NaN" And e.Position.Longitude.ToString() <> "NaN" Then

            StatusBar2.Text = "Position has changed."

            oCurrentGpsPosition.latitude = e.Position.Latitude.DecimalDegrees
            oCurrentGpsPosition.longitude = e.Position.Longitude.DecimalDegrees

            Latitude.Text = e.Position.Latitude.ToString
            Longitude.Text = e.Position.Longitude.ToString

            If (frmUtilityTracks.Txt_TrackStatus.Text = "true") Then
                If (DateDiff(DateInterval.Second, oldDateTimeTrackRec, Now) > 5) Then
                    oldDateTimeTrackRec = Now
                    AfficherDataTrack()
                End If
            End If
        End If
    End Sub

    Private Sub NmeaInterpreter1_UtcDateTimeChanged(ByVal sender As System.Object, ByVal e As GeoFramework.DateTimeEventArgs)
        BeginInvoke(New Action(Of Object, GeoFramework.DateTimeEventArgs)(AddressOf UtcDateTimeChanged), sender, e)
    End Sub

    Private Sub UtcDateTimeChanged(ByVal sender As Object, ByVal e As GeoFramework.DateTimeEventArgs)
        ' Update the current satellite-derived time
        SatelliteTime.Text = e.DateTime.ToLocalTime().ToString()
    End Sub

    Private Sub NmeaInterpreter1_Paused(ByVal sender As System.Object, ByVal e As System.EventArgs)
        BeginInvoke(New Action(Of Object, System.EventArgs)(AddressOf Paused), sender, e)

    End Sub

    Private Sub Paused(ByVal sender As Object, ByVal e As System.EventArgs)
        StatusBar2.Text = "Device was powered off!"
        Cursor.Current = Cursors.WaitCursor
    End Sub

    Private Sub NmeaInterpreter1_BearingChanged(ByVal sender As System.Object, ByVal e As GeoFramework.AzimuthEventArgs)
        BeginInvoke(New Action(Of Object, GeoFramework.AzimuthEventArgs)(AddressOf BearingChanged), sender, e)

    End Sub

    Private Sub BearingChanged(ByVal sender As Object, ByVal e As GeoFramework.AzimuthEventArgs)
        'Compass1.Value = e.Azimuth
        frmUtilitycompass.Compass1.Value = e.Azimuth
        'Output the current bearing as degrees (i.e. 012°)
        Bearing.Text = e.Azimuth.ToString()
        'Output the current bearing as a compass direction (i.e. Southwest)
        Direction.Text = e.Azimuth.ToString("c")
        StatusBar2.Text = "Bearing has changed."

    End Sub

    Private Sub NmeaInterpreter1_VerticalDilutionOfPrecisionChanged(ByVal sender As System.Object, ByVal e As GeoFramework.Gps.DilutionOfPrecisionEventArgs)
        BeginInvoke(New Action(Of Object, GeoFramework.Gps.DilutionOfPrecisionEventArgs)(AddressOf VerticalDilutionOfPrecisionChanged), sender, e)

    End Sub

    Private Sub VerticalDilutionOfPrecisionChanged(ByVal sender As Object, ByVal e As GeoFramework.Gps.DilutionOfPrecisionEventArgs)
        ' Update the vertical DOP on the track bar
        StatusBar2.Text = "Altitude precision has changed."
    End Sub

    Private Sub NmeaInterpreter1_SatellitesChanged(ByVal sender As System.Object, ByVal e As GeoFramework.Gps.SatelliteListEventArgs)
        BeginInvoke(New Action(Of Object, GeoFramework.Gps.SatelliteListEventArgs)(AddressOf SatellitesChanged), sender, e)

    End Sub

    Private Sub SatellitesChanged(ByVal sender As Object, ByVal e As GeoFramework.Gps.SatelliteListEventArgs)
        'SatelliteViewer1.Satellites = TryCast(e.Satellites, List(Of Satellite))
        frmUtilitycompass.SatelliteViewer1.Satellites = TryCast(e.Satellites, List(Of Satellite))
        'SatelliteSignalBar1.Satellites = TryCast(e.Satellites, List(Of Satellite))
    End Sub

#End Region

#Region "Connection et Deconnection"

    Private Sub StartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartButton.Click
        'Test si un appareil est détecté et sélectionné 
        If DevicesListView.SelectedIndices.Count = 0 Then
            MessageBox.Show("You have to select a GPS device")
            Return
        End If

        ' Find out which item is selected in the list view
        Dim SelectedItem As ListViewItem = DevicesListView.Items(DevicesListView.SelectedIndices(0))

        ' The "tag" property holds the device that was detected
        Dim selectedDevice As Device = DirectCast(SelectedItem.Tag, Device)
        oCurrentDevice = selectedDevice

        Try
            NmeaInterpreter1.Start(selectedDevice)
            AddHandler selectedDevice.Connecting, AddressOf Device_Connecting
            AddHandler selectedDevice.Connected, AddressOf Device_Connected

            StartButton.Enabled = False
            SearchButton.Enabled = False


            ' Enable the disconnect button
            StopButton.Enabled = True

            GpsStatus = CtlLightGPSTrack.GpsLightStatus.statusOnWithoutSignal
            ChangeCtlLightGpsStatus(GpsStatus)
            m_isGpsInterpreteurOpen = True
            blGpsON = True

        Catch ex As Exception
            MessageBox.Show(ex.ToString(), "Connection failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        End Try

        ' Finally, start the interpreter using the newly-assigned Stream

    End Sub
    Private Sub StopButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopButton.Click
        StopGPS(True)
    End Sub

    Public Sub StopGPS(ByVal booOnCLose As Boolean)
        ' arreter toute communication
        NmeaInterpreter1.Stop()
        If (booOnCLose) Then
            m_isGpsInterpreteurOpen = False
            StartButton.Enabled = True
            ' désactiver le bouton deconnexion
            StopButton.Enabled = False
            StatusBar2.Text = "Disconnecting the GPS ..."
            blGpsON = False
            StatusBar2.Text = "Disconnected."
            GpsStatus = CtlLightGPSTrack.GpsLightStatus.statusOff
            ChangeCtlLightGpsStatus(GpsStatus)
            CalculatePrecision(50, Me.preci_cadre.Width, Preci)
            LabelTxtSignalQuality.Text = "No signal"
        End If
    End Sub

    Private Sub DevicesListView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DevicesListView.SelectedIndexChanged
        StartButton.Enabled = True
        StartButton.Focus()
    End Sub

    Sub Device_Connecting(ByVal sender As Object, ByVal e As EventArgs)
        Cursor.Current = Cursors.WaitCursor
        StatusBar2.Text = "Connection to the GPS device ..."
        GpsStatus = CtlLightGPSTrack.GpsLightStatus.statusOnWithoutSignal
        ChangeCtlLightGpsStatus(GpsStatus)
        m_isGpsInterpreteurOpen = True
        blGpsON = True
    End Sub

    Sub Device_Connected(ByVal sender As Object, ByVal e As EventArgs)
        StatusBar2.Text = "Connected to the GPS! Reading data ..."
        Cursor.Current = Cursors.[Default]
    End Sub

#End Region
#Region "Working with Raw Data"

    Public Sub NmeaInterpreter1_SentenceReceived(ByVal sender As System.Object, ByVal e As GeoFramework.Gps.Nmea.NmeaSentenceEventArgs)
        BeginInvoke(New Action(Of Object, GeoFramework.Gps.Nmea.NmeaSentenceEventArgs)(AddressOf SentenceReceived), sender, e)

    End Sub


    Private Sub SentenceReceived(ByVal sender As Object, ByVal e As GeoFramework.Gps.Nmea.NmeaSentenceEventArgs)
        m_isGpsInterpreteurOpen = True
        blGpsON = True
    End Sub


#End Region

#Region "Dilution Of Precision"

    'Private Sub MaximumVdopTrackBar_ValueChanged(ByVal sender As Object, ByVal e As EventArgs)

    '    If MaximumVdopTrackBar.Value > MaximumVdopTrackBar.Maximum Then

    '        MaximumVdopTrackBar.Value = MaximumVdopTrackBar.Maximum

    '    ElseIf MaximumVdopTrackBar.Value <= MaximumVdopTrackBar.Minimum Then

    '        MaximumVdopTrackBar.Value = MaximumVdopTrackBar.Minimum + 1

    '        If MaximumVdopTrackBar.Value = 0 Then

    '            MaximumVdopTrackBar.Value = 1

    '        End If

    '    End If

    '    ' Set the new maximum altitude precision error

    '    NmeaInterpreter1.MaximumVerticalDilutionOfPrecision = New DilutionOfPrecision(MaximumVdopTrackBar.Value)

    '    ' And update the UI

    '    UpdateDopStatus()

    'End Sub



    'Private Sub MaximumHdopTrackBar_ValueChanged(ByVal sender As Object, ByVal e As EventArgs)

    '    If MaximumHdopTrackBar.Value > MaximumHdopTrackBar.Maximum Then

    '        MaximumHdopTrackBar.Value = MaximumHdopTrackBar.Maximum

    '    ElseIf MaximumHdopTrackBar.Value <= MaximumHdopTrackBar.Minimum Then

    '        MaximumHdopTrackBar.Value = MaximumHdopTrackBar.Minimum

    '        If MaximumHdopTrackBar.Value = 0 Then

    '            MaximumHdopTrackBar.Value = 1

    '        End If

    '    End If

    '    ' Set the new maximum latitude/longitude precision error

    '    NmeaInterpreter1.MaximumHorizontalDilutionOfPrecision = New DilutionOfPrecision(MaximumHdopTrackBar.Value)

    '    ' And update the UI

    '    UpdateDopStatus()

    'End Sub

#End Region


    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        LocalTime.Text = DateTime.Now.ToString()
    End Sub


    Private Sub btnRetourMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRetourMenu.Click
        FormMain.Show()
        Me.Hide()
    End Sub

    Private Sub btnRetour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRetour.Click
        frmParamChoix.Show()
        Me.Hide()
    End Sub

    Private Sub AfficherDataTrack()
        Dim wTrack As String
        If ((Not IsNothing(oCurrentGpsPosition.dopH)) And (Not IsNothing(oCurrentGpsPosition.latitude)) _
            And (Not IsNothing(oCurrentGpsPosition.longitude))) Then
            If (oCurrentGpsPosition.dopH <= 50) Then
                Dim DateNom As String = Now.ToString("yyyy-MM-ddTHH:mm:ssZ")

                If frmUtilityTracks.Txt_TrackStatus.Text = "true" Then
                    wTrack = "<trkpt lat=" & """" & ChangeDecimalSeparator(oCurrentGpsPosition.latitude.ToString, ",", ".") & """" & "  lon=" & """" & _
                        ChangeDecimalSeparator(oCurrentGpsPosition.longitude.ToString, ",", ".") & """" & " > " & _
                        "<ele>" & ChangeDecimalSeparator(oCurrentGpsPosition.altitude.ToString, ",", ".") & "</ele> <time>" & DateNom & "</time> </trkpt>"
                    ' Sauvegarde automatique toute les 1000 caractères
                    If (Len(frmUtilityTracks.lb_Track.Text) >= 10000) Then
                        SaveTrack(FormMain.NSDossier & "TrackGPS_" & Now.ToString("yyMMdd") & ".gpx", FormMain.NSDossier, False)
                        frmUtilityTracks.lb_Track.Text = ""
                    End If
                    frmUtilityTracks.lb_Track.Text = frmUtilityTracks.lb_Track.Text + Chr(10) + wTrack.ToString
                End If
                'Else : frmDataTracks.lb_Track.Text = "null"
            End If
        End If
    End Sub

    Private Sub frmParamGPS_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If (e.KeyCode = System.Windows.Forms.Keys.Up) Then
            'Up
        End If
        If (e.KeyCode = System.Windows.Forms.Keys.Down) Then
            'Down
        End If
        If (e.KeyCode = System.Windows.Forms.Keys.Left) Then
            'Left
        End If
        If (e.KeyCode = System.Windows.Forms.Keys.Right) Then
            'Right
        End If
        If (e.KeyCode = System.Windows.Forms.Keys.Enter) Then
            'Enter
        End If

    End Sub


    Private Sub frmParamGPS_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txt_currentprecisionH.Text = "NO"
    End Sub
End Class
